define(function(require, exports){
	// var $ = require("jquery");
	var pubjs = require('pubjs');
	var view  = require('@base/view');
	var util  = require('util');

	var Main = view.container.extend({
		init:function(config){
			//是否有更新资质审核状态的权限
			var showGetResult = pubjs.checkRight('qualificationGetResult') || false;
			config = pubjs.conf(config, {
				// 腾讯渠道审核状态url
				'urlTenctent': '',
				// 百度渠道审核状态url
				'urlBaidu': '',
				// 新浪渠道审核状态url
				'urlSina': '',
				'verifyUrl': 'qualification/getVerifyState',
				'class': 'P-adminAptitudeList',
				'view_model': {
					'showGetResult': showGetResult
				}
			});
			this.Super('init', arguments);
		},
		afterBuild:function(){
			var self = this;
			var c = this.getConfig();

			self.append([
				// '<div class="M-formHead">',
				// 	'<span class="ml10" pub-name="back" pub-mod="@base/common/drop.add" ></span>',
				// 	'<span class="ml10" pub-name="update" pub-mod="@base/common/drop.add" ></span>',
				// '</div>',
				'<div class="cl" pub-name="grid" pub-mod="admin/aptitude/grid/verifyList.base"/>'
			].join(''));

			self.buildFromTemplate({
				'grid': {
					'hasSearch': true,
					'hasFilter': false
				},
				// 'update': {
				// 	'def': LANG('手动更新状态'),
				// 	'icon': 'icon-spinner',
				// 	'useCallback': true
				// },
				// 'back': {
				// 	'def': LANG('返回'),
				// 	// 'icon': 'icon-setting2',
				// 	'href': '#admin/aptitude',
				// 	'href_target': '_self'
				// }
			});

			this.createAsync('slotSidebar', '@layout/v1/sidebar.base', {
				'target': c.targetSidebar,
				'items': [

				]
			});
		},
		// 获取在审核状态的渠道
		getAptitudeGroup: function() {
			var data = this.$.grid.getData();
			var result = [];
			util.each(data.items, function(item) {
				var tmp = {};
				tmp['Id'] = item._id;
				util.each(item.Info, function(item_info){
					if(item_info && !item_info.IsDeleted && (+item_info.Status != 1 || +item_info.Status !== 0)){
						if(!tmp['ExchangeIds']){
							tmp['ExchangeIds'] = [];
						}
						tmp['ExchangeIds'].push(item_info.ExchangeId);
					}
				});
				if(tmp['ExchangeIds'] && tmp['ExchangeIds'].length){
					result.push(tmp);
				}
			});
			return result;
		},
		// 手动更新审核状态
		refreshStatus: function() {
			var self = this;
			var url = self.getConfig('verifyUrl');
			self.showLoading();
			var data = self.getAptitudeGroup();

			pubjs.mc.send(url, data, self.afterRefreshStatus.bind(self));
		},
		afterRefreshStatus: function(err, data) {
			this.hideLoading();
			if(err){
				pubjs.error(err.message);
			}
			this.$.grid.load();
		},
		onInputClick: function(ev){
			// 手动更新状态按钮点击事件
			if(ev.name == 'update'){
				this.refreshStatus();
			}

			return false;
		}
	});
	exports.main = Main;
});